<?php
namespace Home\Controller;

use Util\AccessController;

class ChildrenController extends AccessController {

    /*
     * 获取用户所有孩子信息
     */
    public function GetMySon() {
        $where['user_id'] = $_POST['user_id'];
        $LS = Service('Children', 'u_children');
        $data = $LS->query($where);
        $DATA = ResData($data);
        $this->ajaxReturn($DATA, 'JSON');
    }

    /*
     * 修改用户孩子信息
     */

    public function UpdateSon() {
        $where['user_id'] = $_POST['user_id'];
        $save = $_POST;
        $LS = Service('Children', 'u_children');
        $data = $LS->update($where, $save);
        $DATA = ResData($data);
        $this->ajaxReturn($DATA, 'JSON');
    }

    /*
     * 添加孩子
     * user_id 用户ID
     *children_name 	孩子名字
     *children_sex 性别（1：男，2：女）
     *
     */
    public function AddSon() {
        $save = $_POST;
        $save['children_id'] = 'c_' . uniqid() . rand(0, 9);
        $save['isSelected'] = 2;
        $LS = Service('Children', 'u_children');
        $data = $LS->insert($save);
        $DATA = ResData($data);
        $this->ajaxReturn($DATA, 'JSON');
    }

}